<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>{$_title}</h2>
    </div>
    <div class="form-horizontal" style="position: relative;">
        <div class="form-item">
            <label class="item-label">文件类型：<span class="check-tips"><select id="file_type" class="input-large">
            		<foreach name="fileType" key="key" item="val">
            			<if condition="$file['fileType'] eq $key">
            				<option value="{$key}" selected>{$val}</option>
            			<else />
            				<option value="{$key}">{$val}</option>
            			</if>
            		</foreach>
            	</select>　
            	<button class="btn" style="margin-bottom:10px;" onclick="saveFile()">保存</button>
            	<button class="btn" style="margin-bottom:10px;" onclick="javascript:history.back(-1);return false;">返 回</button>
            </span></label>
        </div>
	    <notempty name="file" >
	    	<input type="hidden" id="id" value="{$file.id}" />
	    	
	    	<notempty name="file">
	        	<div class="form-item">
            		<label class="item-label">文件名称：<span class="check-tips"><input type="text" class="text input-large" id="name" value="{$file.name|default=''}"></span></label>
        		</div>
	    	<else />
		    	<div class="form-item">
		            <label class="item-label">文件名称：<span class="check-tips">{$file.name|default=''}</span></label>
		        </div>
	    	</notempty>
	        <div class="form-item">
	            <label class="item-label">文件大小：<span class="check-tips">{$file.size_format|default=''}</span></label>
	        </div>
	        <div class="form-item">
	            <label class="item-label">文件类型：<span class="check-tips">{$file.ext|default=''}</span></label>
	        </div>
	        <notempty name="file['picture']">
		        <div class="form-item">
		            <label class="item-label">图片预览<span class="check-tips"></span></label>
		            <div class="controls">
		                <img src="{$file.url}"/>
		            </div>
		        </div>
	        </notempty>
	        <div  style="position: absolute; top:35px; left:490px;">
	        	<input type="file" class="text input-large" id="upload" value="">
    		</div>
	        <notempty name="file['picture']">
		        <div class="form-item">
		            <label class="item-label">图片预览<span class="check-tips"></span></label>
		            <div class="controls">
		                <img src="{$file.url}"/>
		            </div>
		        </div>
		    <else />
				<div class="form-item">
		            <label class="item-label">文件预览：<span class="check-tips"><a href="{$file.url|default=''}">查看文件</a></span></label>
		        </div>
	        </notempty>
	    <else />
	    	<div  style="position: absolute; top:35px; left:490px;">
	        	<input type="file" class="text input-large" id="upload" value="">
    		</div>
	    </notempty>
   </div>
</block>
<block name="style">
	<link href="__PUBLIC__/static/uploadify/uploadify.css" rel="stylesheet" media="screen">
</block>
<block name="script">
<script type="text/javascript" src="__PUBLIC__/static/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript">
    /* 初始化上传插件 */
	$("#upload").uploadify({
        "height"          : 30,
        "swf"             : "__STATIC__/uploadify/uploadify.swf",
        "fileObjName"     : "download",
        //"auto"			  : false,
        "buttonText"      : "{$buttonText|default='上传文件...'}",
        "fileTypeExts"	  : "{$fileLimit.ext}",
        "fileSizeLimit"	  : "{$fileLimit.size}",
        "uploader"        : "{:U('AppTest/addFile',array('session_id'=>session_id()))}",
        "width"           : 120,
        'removeTimeout'	  : 1,
        'onFallback' : function() {
            alert('未检测到兼容版本的Flash.');
        },
        "onUploadStart":function(){
        	var formData = $("#upload").uploadify("settings", "formData");
        	formData['file_type'] = $("#file_type").val();
        	var id = $("#id").val();
        	if(id) formData['id'] = id;
        	$('#upload').uploadify('settings','formData',formData);
        },
        "onUploadSuccess" : function(file,data){
        	var data = $.parseJSON(data);
        	jsonDataDialog(data, {success:function(data){
        		window.location.href = "__SELF__";
        	}});
        },
    });
    
	//修改文件信息
	function saveFile()
	{
		var param = {};
		param['id'] = $("#id").val();
		param['fileType'] = $("#file_type").val();
		param['name'] = $("#name").val();
		ajaxRequest('{:U("File/editFile")}', param, {'type':'post','func':function(data){
			jsonDataDialog(data);
		}});
	}
	
</script>
</block>
